package com.data.basic.chapter07;

import sun.reflect.generics.tree.Tree;

import java.util.Set;
import java.util.TreeSet;

/**  leetCode  804题  摩斯密码
 * Created by wangbing on 2018/5/15.
 */
public class Solution {
    public int uniqueMorseRepresentations(String[] words) {
        String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        TreeSet<String> set = new TreeSet<String>();

        for (String word :
                words) {
            StringBuilder res = new StringBuilder();
            for (int i=0;i<word.length();i++){
                res.append(codes[word.charAt(i)-'a']);
            }
            set.add(res.toString());
        }

        return set.size();
    }
}
